<template>
  <el-table-column
    :align="align"
    :label="label"
    :resizable="resizable"
  >
    <template slot-scope="scope">
      <span>{{ scope.row.id }}</span>
    </template>
  </el-table-column>
</template>

<script>
import { scrollTo } from '@/utils/extends/scroll-to'

export default {
  name: 'Column',
  props: {
    attribute: {
      type: String,
      required: true
    },
    label: {
      type: String,
      default: ''
    },
    align: {
      type: String,
      default: ''
    },
    resizable: {
      type: Boolean,
      default: false
    },
    pageSizes: {
      type: Array,
      default() {
        return [10, 20, 30, 50]
      }
    },
    layout: {
      type: String,
      default: 'total,  prev, pager, next, jumper'
      // default: 'total, sizes, prev, pager, next, jumper'
    },
    background: {
      type: Boolean,
      default: true
    },
    autoScroll: {
      type: Boolean,
      default: true
    },
    hidden: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    currentPage: {
      get() {
        return this.page
      },
      set(val) {
        this.$emit('update:page', val)
      }
    },
    column: {
      get() {
        return this.limit
      },
      set(val) {
        this.$emit('update:limit', val)
      }
    }
  },
  methods: {
    handleSizeChange(val) {
      this.$emit('pagination', { page: this.currentPage, limit: val })
      if (this.autoScroll) {
        scrollTo(0, 800)
      }
    },
    handleCurrentChange(val) {
      this.$emit('pagination', { page: val, limit: this.pageSize })
      if (this.autoScroll) {
        scrollTo(0, 800)
      }
    }
  }
}
</script>

<style lang='scss' scoped>
.pagination-container {
  background: #fff;
  padding: 32px 0;
  .el-pagination {
    padding: 2px 0;
    text-align: right;
  }
}
.pagination-container.hidden {
  display: none;
}
</style>
